//
//  AppTabBarController.m
//  ApeExample
//
//  Created by Eton on 2017/7/27.
//  Copyright © 2017年 王-庭协. All rights reserved.
//

#import "AppTabBarController.h"
#import "HomeViewController.h"
#import "MineViewController.h"
#import "ModulesViewController.h"

@interface AppTabBarController ()<UITabBarControllerDelegate>

@end

@implementation AppTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.delegate = self;
    
    [self setupTabBar];
    
    [self setupViewControllers];
    
}

/**
 * 自定义tabBar
 */
- (void)setupTabBar {
    self.tabBar.shadowImage = [UIImage tx_imageWithColor:gTabBarLineColor];
    self.tabBar.backgroundImage = [UIImage tx_imageWithColor:gTabBarBackgroundColor];
    self.tabBar.tintColor = gTabBarTintColor;
}

- (void)setupViewControllers{
    
    _HomeVC = [[HomeViewController alloc] init];
    [_HomeVC setTabBarItemTitle:@"猿人框架" imageName:@"menu1" selectedImageName:@"menu1a"];
    _ModulesVC = [[ModulesViewController alloc] init];
    [_ModulesVC setTabBarItemTitle:@"模块" imageName:@"menu2" selectedImageName:@"menu2a"];
    _MineVC = kVCFromSb(@"Mine", @"MineViewController");
    [_MineVC setTabBarItemTitle:@"我的" imageName:@"menu4" selectedImageName:@"menu4a"];
    
    ApeNavigationController * NC1 = [[ApeNavigationController alloc] initWithRootViewController:_HomeVC];
    ApeNavigationController * NC2 = [[ApeNavigationController alloc] initWithRootViewController:_ModulesVC];
    ApeNavigationController * NC4 = [[ApeNavigationController alloc] initWithRootViewController:_MineVC];
    
    NSMutableArray *viewControllers = [NSMutableArray arrayWithArray:@[NC2,
                                                                       NC1,
                                                                       NC4
                                                                       ]];
    self.viewControllers = viewControllers;
}

//- (void)setupData{
//    
//    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setupUnreadMessageCount) name:K_SETUP_UNREAD_MESSAGE_COUNT_NOTIFICATION object:nil];
//    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setupUnreadMessageCount) name:K_RECEIVED_APNS_NOTIFICATION object:nil];
//    [self setupUnreadMessageCount];
//}


//// 统计未读消息数
//-(void)setupUnreadMessageCount
//{
//    //    NSArray *conversations = [[EMClient sharedClient].chatManager getAllConversations];
//    //    NSInteger unreadCount = 0;
//    //    for (EMConversation *conversation in conversations) {
//    //        unreadCount += conversation.unreadMessagesCount;
//    //    }
//    //    unreadCount += kGlobalData.announUnreadMessagesCount;
//    //    if (self.messageVC) {
//    //        if (unreadCount > 0) {
//    //            self.messageVC.tabBarItem.badgeValue = [NSString stringWithFormat:@"%i",(int)unreadCount];
//    //        }else{
//    //            self.messageVC.tabBarItem.badgeValue = nil;
//    //        }
//    //    }
//    //
//    //    UIApplication *application = [UIApplication sharedApplication];
//    //    [application setApplicationIconBadgeNumber:unreadCount];
//}


- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{
    return YES;
};

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
